
using Youz.Common.DBUtility;
using Youz.Common.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.Common.DAL
{
    /// <summary>
    /// Lang_LanguageType Data Class
    /// </summary>
    public partial class Lang_LanguageTypeDAL : BaseDAL
    {
        private DbHelperSQL DbHelperSQL = new DbHelperSQL(!string.IsNullOrEmpty(PubConstant.connStr_Lang) ? PubConstant.connStr_Lang : PubConstant.connStr);

        public string TableName = "Lang_LanguageType";

        public Lang_LanguageTypeDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Lang_LanguageType model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Lang_LanguageType](");
            strSql.Append("[LanguageCode],[LanguageName],[Icon],[DateFormat],[IsEnable],[IsDefault],[CreateTime],[Creator],[ModifiedTime],[Modifier]");
            strSql.Append(") values (");
            strSql.Append("@LanguageCode,@LanguageName,@Icon,@DateFormat,@IsEnable,@IsDefault,@CreateTime,@Creator,@ModifiedTime,@Modifier");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@LanguageCode", model.LanguageCode),
                    new SqlParameter("@LanguageName", model.LanguageName),
                    new SqlParameter("@Icon", model.Icon),
                    new SqlParameter("@DateFormat", model.DateFormat),
                    new SqlParameter("@IsEnable", model.IsEnable),
                    new SqlParameter("@IsDefault", model.IsDefault),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Creator", model.Creator),
                    new SqlParameter("@ModifiedTime", model.ModifiedTime),
                    new SqlParameter("@Modifier", model.Modifier)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Lang_LanguageType model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Lang_LanguageType] set ");
            strSql.Append("[LanguageName]=@LanguageName,[Icon]=@Icon,[DateFormat]=@DateFormat,[IsEnable]=@IsEnable,[IsDefault]=@IsDefault,[CreateTime]=@CreateTime,[Creator]=@Creator,[ModifiedTime]=@ModifiedTime,[Modifier]=@Modifier");
            strSql.Append(" where [LanguageCode]=@LanguageCode");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@LanguageCode", model.LanguageCode),
                    new SqlParameter("@LanguageName", model.LanguageName),
                    new SqlParameter("@Icon", model.Icon),
                    new SqlParameter("@DateFormat", model.DateFormat),
                    new SqlParameter("@IsEnable", model.IsEnable),
                    new SqlParameter("@IsDefault", model.IsDefault),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Creator", model.Creator),
                    new SqlParameter("@ModifiedTime", model.ModifiedTime),
                    new SqlParameter("@Modifier", model.Modifier)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(String LanguageCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Lang_LanguageType] ");
            strSql.Append(" where [LanguageCode]=@LanguageCode");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@LanguageCode", LanguageCode)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Lang_LanguageType Get(String LanguageCode)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Lang_LanguageType] ");
            strSql.Append(" where [LanguageCode]=@LanguageCode");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("LanguageCode", LanguageCode)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Lang_LanguageType Get(DataRow row)
        {
            if (row == null) return null;

            Lang_LanguageType model = new Lang_LanguageType();
	
            
            if (row["LanguageCode"] != DBNull.Value)
            {
                model.LanguageCode = (String)row["LanguageCode"];
            }      
            
            if (row["LanguageName"] != DBNull.Value)
            {
                model.LanguageName = (String)row["LanguageName"];
            }      
            
            if (row["Icon"] != DBNull.Value)
            {
                model.Icon = (String)row["Icon"];
            }      
            
            if (row["DateFormat"] != DBNull.Value)
            {
                model.DateFormat = (String)row["DateFormat"];
            }      
            
            if (row["IsEnable"] != DBNull.Value)
            {
                model.IsEnable = (Boolean)row["IsEnable"];
            }      
            
            if (row["IsDefault"] != DBNull.Value)
            {
                model.IsDefault = (Boolean)row["IsDefault"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            
            if (row["Creator"] != DBNull.Value)
            {
                model.Creator = (String)row["Creator"];
            }      
            
            if (row["ModifiedTime"] != DBNull.Value)
            {
                model.ModifiedTime = (DateTime)row["ModifiedTime"];
            }      
            
            if (row["Modifier"] != DBNull.Value)
            {
                model.Modifier = (String)row["Modifier"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable Gets(string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Lang_LanguageType]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), cmdParms);
            if (ds != null && ds.Tables.Count >= 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return new DataTable();
            }
        }
      #endregion  成员方法

      
    }
}


  